﻿using Polly;
using System;
namespace HBKY.Shop.Common.PollyHelper.PollyAttribute
{
    public class CustomPollyRetryAttribute : PollyRetryAttribute
    {
        //在这里定义策略，对外提供策略
        public override Action<ISyncPolicy> Do(Action<ISyncPolicy> action)
        {
            Policy retryPolicy = Policy.Handle<Exception>().Retry(retryCount: 3, (exception, count) =>
            {
                LogHelper.LogManagerNlog.LogError(exception, $"Message:{exception.Message} 重试Count:{count}");
            });
            return s =>
            {
                Policy policy = null;
                if (s == null) policy = retryPolicy;
                else policy = Policy.Wrap(s, retryPolicy);
                action(policy);
            };

        }
    }
}
